Use --emit=metadata rather than --crate-type=metadata
authorNick Cameron <ncameron@mozilla.com>
Wed, 28 Dec 2016 21:30:34 +0000 (10:30 +1300)
committerNick Cameron <ncameron@mozilla.com>
Wed, 4 Jan 2017 22:02:20 +0000 (11:02 +1300)
Requires https://github.com/rust-lang/rust/pull/38571

src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/util/cfg.rs

index 1185fd64a8f23af5fa9200bfbeb50b2cdc58bf2b..a5a16b4791d672411cf6cfca1945ef58f6bf9583 100644 (file)
@@ -146,9 +146,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                         unit: &Unit<'a>,
                         crate_types: &mut BTreeSet<String>)
                         -> CargoResult<()> {
-        if unit.profile.check {
-            crate_types.insert("metadata".to_string());
-        }
         for target in unit.pkg.manifest().targets() {
             crate_types.extend(target.rustc_crate_types().iter().map(|s| {
                 if *s == "lib" {
@@ -180,11 +177,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                .env_remove("RUST_LOG");
 
         for crate_type in crate_types {
-            // Here and below we'll skip the metadata crate-type because it is
-            // not supported by older compilers. We'll do this one manually.
-            if crate_type != "metadata" {
-                process.arg("--crate-type").arg(crate_type);
-            }
+            process.arg("--crate-type").arg(crate_type);
         }
         if kind == Kind::Target {
             process.arg("--target").arg(&self.target_triple());
@@ -216,9 +209,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                 map.insert(crate_type.to_string(), None);
                 continue;
             }
-            if crate_type == "metadata" {
-                continue;
-            }
             let line = match lines.next() {
                 Some(line) => line,
                 None => bail!("malformed output when learning about \
@@ -235,12 +225,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string())));
         }
  
-        // Manually handle the metadata case. If it is not supported by the
-        // compiler we'll error out elsewhere.
-        if crate_types.contains("metadata") {
-            map.insert("metadata".to_string(), Some(("lib".to_owned(), ".rmeta".to_owned())));
-        }
-
         let cfg = if has_cfg {
             Some(try!(lines.map(Cfg::from_str).collect()))
         } else {
@@ -502,32 +486,36 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         let mut ret = Vec::new();
         let mut unsupported = Vec::new();
         {
-            let mut add = |crate_type: &str, linkable: bool| -> CargoResult<()> {
-                let crate_type = if crate_type == "lib" {"rlib"} else {crate_type};
-                match info.crate_types.get(crate_type) {
-                    Some(&Some((ref prefix, ref suffix))) => {
-                        let filename = out_dir.join(format!("{}{}{}", prefix, stem, suffix));
-                        let link_dst = link_stem.clone().map(|(ld, ls)| {
-                            ld.join(format!("{}{}{}", prefix, ls, suffix))
-                        });
-                        ret.push((filename, link_dst, linkable));
-                        Ok(())
-                    }
-                    // not supported, don't worry about it
-                    Some(&None) => {
-                        unsupported.push(crate_type.to_string());
-                        Ok(())
-                    }
-                    None => {
-                        bail!("failed to learn about crate-type `{}` early on",
-                              crate_type)
-                    }
-                }
-            };
-
             if unit.profile.check {
-                add("metadata", true)?;
+                let filename = out_dir.join(format!("lib{}.rmeta", stem));
+                let link_dst = link_stem.clone().map(|(ld, ls)| {
+                    ld.join(format!("lib{}.rmeta", ls))
+                });
+                ret.push((filename, link_dst, true));
             } else {
+                let mut add = |crate_type: &str, linkable: bool| -> CargoResult<()> {
+                    let crate_type = if crate_type == "lib" {"rlib"} else {crate_type};
+                    match info.crate_types.get(crate_type) {
+                        Some(&Some((ref prefix, ref suffix))) => {
+                            let filename = out_dir.join(format!("{}{}{}", prefix, stem, suffix));
+                            let link_dst = link_stem.clone().map(|(ld, ls)| {
+                                ld.join(format!("{}{}{}", prefix, ls, suffix))
+                            });
+                            ret.push((filename, link_dst, linkable));
+                            Ok(())
+                        }
+                        // not supported, don't worry about it
+                        Some(&None) => {
+                            unsupported.push(crate_type.to_string());
+                            Ok(())
+                        }
+                        None => {
+                            bail!("failed to learn about crate-type `{}` early on",
+                                  crate_type)
+                        }
+                    }
+                };
+
                 match *unit.target.kind() {
                     TargetKind::Example |
                     TargetKind::Bin |
index 24f9deb0a80da27498fdd7bdcdc6b4acdbfa1b9b..24c3de65697ace7eca423bb0e9058bbe8829c8d9 100644 (file)
@@ -460,7 +460,6 @@ fn prepare_rustc(cx: &mut Context,
                  unit: &Unit) -> CargoResult<ProcessBuilder> {
     let mut base = cx.compilation.rustc_process(unit.pkg)?;
     build_base_args(cx, &mut base, unit, &crate_types);
-    build_plugin_args(&mut base, cx, unit);
     build_deps_args(&mut base, cx, unit)?;
     Ok(base)
 }
@@ -566,14 +565,18 @@ fn build_base_args(cx: &mut Context,
         cmd.arg("--error-format").arg("json");
     }
 
-    if check {
-        cmd.arg("--crate-type").arg("metadata");
-    } else if !test {
+    if !test {
         for crate_type in crate_types.iter() {
             cmd.arg("--crate-type").arg(crate_type);
         }
     }
 
+    if check {
+        cmd.arg("--emit=dep-info,metadata");
+    } else {
+        cmd.arg("--emit=dep-info,link");
+    }
+
     let prefer_dynamic = (unit.target.for_host() &&
                           !unit.target.is_custom_build()) ||
                          (crate_types.contains(&"dylib") &&
@@ -653,10 +656,9 @@ fn build_base_args(cx: &mut Context,
     if rpath {
         cmd.arg("-C").arg("rpath");
     }
-}
 
+    cmd.arg("--out-dir").arg(&cx.out_dir(unit));
 
-fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
     fn opt(cmd: &mut ProcessBuilder, key: &str, prefix: &str,
            val: Option<&OsStr>)  {
         if let Some(val) = val {
@@ -666,9 +668,6 @@ fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
         }
     }
 
-    cmd.arg("--out-dir").arg(&cx.out_dir(unit));
-    cmd.arg("--emit=dep-info,link");
-
     if unit.kind == Kind::Target {
         opt(cmd, "--target", "", cx.requested_target().map(|s| s.as_ref()));
     }
@@ -677,6 +676,7 @@ fn build_plugin_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit) {
     opt(cmd, "-C", "linker=", cx.linker(unit.kind).map(|s| s.as_ref()));
 }
 
+
 fn build_deps_args(cmd: &mut ProcessBuilder, cx: &mut Context, unit: &Unit)
                    -> CargoResult<()> {
     cmd.arg("-L").arg(&{
index bd89586bc3822112bbfdaf14eff46afcf366f268..a666a07edb0d8acd65eb17279de5a85d156709f6 100644 (file)
@@ -44,7 +44,7 @@ impl FromStr for Cfg {
         let mut p = Parser::new(s);
         let e = p.cfg()?;
         if p.t.next().is_some() {
-            bail!("malformed cfg value or key/value pair")
+            bail!("malformed cfg value or key/value pair: `{}`", s)
         }
         Ok(e)
     }